<template>
  <div class="container">
    <!-- 检查类型选择 -->
    <div class="mb-8">
      <swiper
        :modules="swiperModules"
        :slides-per-view="'auto'"
        :space-between="16"
        class="check-type-swiper"
      >
        <swiper-slide v-for="type in checkTypes" :key="type.id" class="w-40">
          <div
            :class="[
              'p-4 rounded-lg cursor-pointer transition-all duration-300',
              selectedType === type.id
                ? 'bg-blue-50 border-blue-500'
                : 'bg-white border-transparent',
            ]"
            class="border-2"
            @click="selectedType = type.id"
          >
            <img
              :src="type.image"
              class="w-full h-24 object-cover rounded-lg mb-3"
            />
            <p class="text-center text-sm font-medium">{{ type.name }}</p>
          </div>
        </swiper-slide>
      </swiper>
    </div>
    <!-- 日期选择 -->
    <div class="bg-white rounded-lg mb-8">
      <div class="flex items-center justify-between mb-4">
        <h3 class="font-medium text-lg">选择日期</h3>
        <el-icon class="text-gray-400">
          <Calendar />
        </el-icon>
      </div>
      <swiper
        :modules="swiperModules"
        :slides-per-view="'auto'"
        :space-between="16"
        class="date-swiper"
      >
        <swiper-slide v-for="date in dates" :key="date.value"  style="width: 5rem;">
          <div
            :class="[
              'p-3 rounded-lg text-center cursor-pointer transition-all duration-300',
              selectedDate === date.value
                ? 'bg-blue-500 text-white'
                : 'bg-gray-50',
            ]"
            @click="selectedDate = date.value"
          >
            <p class="text-sm mb-1">{{ date.day }}</p>
            <p class="text-xs">{{ date.date }}</p>
          </div>
        </swiper-slide>
      </swiper>
    </div>
    <!-- 常规产检预约  医生排班 -->
    <div class="space-y-4 mb-8" v-if="selectedType == 1">
      <h3 class="font-medium text-lg mb-4">医生排班</h3>
      <div v-for="schedule in schedules" :key="schedule.id" class="div-doctor">
        <el-row class="mb-6">
          <el-col :span="2">
            <el-popover
              placement="right"
              title="专长"
              :width="200"
              trigger="hover"
              :content="schedule.expertise"
            >
              <template #reference>
                <el-avatar
                  :src="schedule.doctorAvatar"
                  :size="50"
                  class="mr-2"
                />
              </template>
            </el-popover>
          </el-col>
          <el-col :span="10">
            <div class="font-medium text-sm">{{ schedule.doctorName }}</div>
            <div class="text-sm text-gray-500">{{ schedule.title }}</div>
          </el-col>
          <el-col :span="11">
            <div class="text-right">
              <p class="text-sm text-gray-500 mb-1">
                {{ schedule.department }}
              </p>
              <p class="text-sm text-blue-500">
                剩余号源：{{ schedule.remaining }}
              </p>
            </div>
          </el-col>
        </el-row>
        <!-- 可预约时间段 -->
        <el-row>
          <el-radio-group class="div-radio">
            <el-button
              text
              type="primary"
              v-for="time in schedule.timeSlots"
              :key="time.id"
              :disabled="time.available"
              class="item2"
              @click="handleAppointment(schedule, time)"
            >
              {{ time.label }}
            </el-button>
          </el-radio-group>
        </el-row>
      </div>
    </div>
    <!-- 彩照预约  科室排班 -->
    <div class="space-y-4 mb-8" v-if="selectedType === 2">
      <h3 class="font-medium text-lg mb-4">彩超可以预约号</h3>
      <!-- 可预约时间段 -->
      <el-row>
        <el-radio-group class="div-radio">
          <el-button
            type="text"
            v-for="time in otherTimeSlots"
            :key="time.label"
            :disabled="time.available"
            class="item2"
            @click="handleAppointment(time)"
          >
            {{ time.label }}
          </el-button>
        </el-radio-group>
      </el-row>
    </div>
    <!-- 无创DNA  科室排班 -->
    <div class="space-y-4 mb-8" v-if="selectedType === 3">
      <h3 class="text-lg font-medium mb-4">DNA无创可以预约时间段</h3>
      <el-row>
        <el-radio-group class="div-radio">
          <el-button
            type="text"
            v-for="time in otherTimeSlots"
            :key="time.label"
            :disabled="time.available"
            class="item2"
            @click="handleAppointment(time)"
          >
            {{ time.label }}
          </el-button>
        </el-radio-group>
      </el-row>
    </div>
    <!-- 唐氏筛查   科室排班 -->
    <div class="space-y-4 mb-8" v-if="selectedType === 4">
      <h3 class="text-lg font-medium mb-4">唐筛可预约时间按段</h3>
      <el-row>
        <el-radio-group class="div-radio">
          <el-button
            type="text"
            v-for="time in otherTimeSlots"
            :key="time.label"
            :disabled="time.available"
            class="item2"
            @click="handleAppointment(time)"
          >
            {{ time.label }}
          </el-button>
        </el-radio-group>
      </el-row>
    </div>
    <!-- 底部操作栏 -->
    <el-row class="bg-white rounded-lg p-6 shadow-sm mb-6">
      <el-affix position="bottom" :offset="25" style="width: 100%">
        <el-row>
          <el-col :span="12">
            <el-popover placement="top" :width="200" trigger="hover">
              <template #reference>
                <el-button
                  :icon="Document"
                  type="info"
                  size="large"
                  @click="appointmentDrawer = true"
                  >预约须知</el-button
                >
              </template>
              <section class="mb-8">
                <el-collapse v-model="activeCollapse">
                  <el-collapse-item
                    title="预约须知（请仔细阅读）"
                    name="notice"
                  >
                    <div class="text-red-600">
                      <p>1. 请至少提前24小时进行预约</p>
                      <p>2. 初诊患者请携带身份证、医保卡等有效证件</p>
                      <p>3. 请准时就诊，如需取消预约请提前2小时告知</p>
                      <p>4. 产检请空腹，并携带相关检查资料</p>
                    </div>
                  </el-collapse-item>
                </el-collapse>
              </section>
            </el-popover>
          </el-col>
          <el-col :span="6" :offset="6" class="text-right">
            <el-button
              color="#3b82f6"
              size="large"
              @click="myAppointmentDrawer = true"
              >我的预约</el-button
            >
          </el-col>
        </el-row>
      </el-affix>
    </el-row>
  </div>
  <!-- 预约须知的抽屉 -->
  <!-- <el-drawer v-model="appointmentDrawer" title="扣费" direction="rtl" size="50%">
        <template #header>
            <h2>预约须知</h2>
        </template>
        <section class="mb-8">
            <el-collapse v-model="activeCollapse">
                <el-collapse-item title="预约须知（请仔细阅读）" name="notice">
                    <div class="text-gray-600">
                        <p>1. 请至少提前24小时进行预约</p>
                        <p>2. 初诊患者请携带身份证、医保卡等有效证件</p>
                        <p>3. 请准时就诊，如需取消预约请提前2小时告知</p>
                        <p>4. 产检请空腹，并携带相关检查资料</p>
                    </div>
                </el-collapse-item>
            </el-collapse>
        </section>
    </el-drawer> -->
  <!-- 我的预约的抽屉 -->
  <el-drawer
    v-model="myAppointmentDrawer"
    title="扣费"
    direction="btt"
    size="50%"
  >
    <template #header>
      <h2>预约须知</h2>
    </template>
    <section class="mb-8">
      <el-table :data="myAppointments" style="width: 100%">
        <el-table-column prop="date" label="就诊时间" width="180" />
        <el-table-column prop="department" label="就诊科室" width="180" />
        <el-table-column prop="doctor" label="就诊医生" width="180" />
        <el-table-column prop="status" label="预约状态">
          <template #default="scope">
            <el-tag
              :type="scope.row.status === '已完成' ? 'success' : 'warning'"
            >
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button
              v-if="scope.row.status === '待就诊'"
              type="danger"
              size="small"
              class="!rounded-button whitespace-nowrap"
              @click="cancelAppointment(scope.row)"
            >
              取消预约
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </section>
  </el-drawer>
</template>

<script setup>
import { ref } from "vue";
import { Swiper, SwiperSlide } from "swiper/vue";
import { Pagination, Autoplay } from "swiper/modules";
import "swiper/css";
import { ArrowLeft, User, Calendar, Document } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";

const swiperModules = [Pagination, Autoplay];

const selectedType = ref(1);
const selectedDate = ref("2024-01-20");

const checkTypes = [
  {
    id: 1,
    name: "常规产检预约",
    image:
      "https://ai-public.mastergo.com/ai/img_res/34c4250fca4ac06b8cecdb14684b596e.jpg",
  },
  {
    id: 2,
    name: "四维彩超预约",
    image:
      "https://ai-public.mastergo.com/ai/img_res/25cd7623860218323baa9227dd892e22.jpg",
  },
  {
    id: 3,
    name: "无创DNA检查",
    image:
      "https://ai-public.mastergo.com/ai/img_res/f45e25357192c4312ba854ce8715ed42.jpg",
  },
  {
    id: 4,
    name: "糖尿病筛查",
    image:
      "https://ai-public.mastergo.com/ai/img_res/41aeec45b8d9bf5ec3527195443e0188.jpg",
  },
];

const otherTimeSlots = [
  { label: "08:30", value: "0830", available: true },
  { label: "09:00", value: "0900", available: true },
  { label: "09:30", value: "0930", available: false },
  { label: "10:00", value: "1000", available: true },
];
const dates = [
  { value: "2024-01-20", day: "周六", date: "01-20" },
  { value: "2024-01-21", day: "周日", date: "01-21" },
  { value: "2024-01-22", day: "周一", date: "01-22" },
  { value: "2024-01-23", day: "周二", date: "01-23" },
  { value: "2024-01-24", day: "周三", date: "01-24" },
  { value: "2024-01-25", day: "周四", date: "01-25" },
  { value: "2024-01-26", day: "周五", date: "01-26" },
];

const schedules = [
  {
    id: 1,
    doctorName: "赵医生",
    title: "主任医师",
    department: "产科门诊",
    remaining: 8,
    expertise: "高危妊娠、产科疑难病症",
    doctorAvatar:
      "https://ai-public.mastergo.com/ai/img_res/447790f07d56883856b9d2e82abcfc84.jpg",
    timeSlots: [
      { label: "08:30", value: "0830", available: true },
      { label: "09:00", value: "0900", available: true },
      { label: "09:30", value: "0930", available: false },
      { label: "10:00", value: "1000", available: true },
    ],
  },
  {
    id: 2,
    doctorName: "钱医生",
    title: "副主任医师",
    department: "产科门诊",
    expertise: "自然分娩、剖宫产手术",
    remaining: 5,
    doctorAvatar:
      "https://ai-public.mastergo.com/ai/img_res/76cc1cd0dc7a7105385c8913fc369e18.jpg",
    timeSlots: [
      { label: "14:00", value: "1400", available: true },
      { label: "14:30", value: "1430", available: false },
      { label: "15:00", value: "1500", available: true },
      { label: "15:30", value: "1530", available: true },
    ],
  },
];

//预约须知
const appointmentDrawer = ref(false);
const myAppointmentDrawer = ref(false);
const activeCollapse = ref(["notice"]);
const myAppointments = ref([
  {
    id: 1,
    date: "2024-01-20 09:30",
    department: "产科门诊",
    doctor: "张晓华",
    status: "已完成",
  },
  {
    id: 2,
    date: "2024-02-15 14:00",
    department: "产科门诊",
    doctor: "刘明珠",
    status: "已取消",
  },
  {
    id: 2,
    date: "2024-02-15 14:00",
    department: "产科门诊",
    doctor: "刘明珠",
    status: "待就诊",
  },
]);
const handleAppointment = (schedule, time) => {
  ElMessage.success(`已成功预约${schedule.doctorName}${time.label}的门诊`);
};

const cancelAppointment = (appointment) => {
  ElMessage.success("取消预约成功");
};
</script>
<style lang="less" scoped>
.check-type-swiper .swiper-slide {
  width: auto;
}

.date-swiper .swiper-slide {
  width: auto;
}

.div-doctor {
  //p-4 border rounded-lg
  // border: 1px solid #ccc;
  padding: 8px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.div-radio {
  // grid grid-cols-4 gap-4 1rem相对于根元素字体大小
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.item2 {
  // border:  1px solid rgb(229,231,235);
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 5px 6px;
  /* Optional: Adds padding inside the divs */
  font-size: 1rem;
}
</style>
